﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Pahan.McuFusion.Common;
using Pahan.McuFusion.UI.Events;
using Pahan.McuFusion.UI.Properties;

namespace Pahan.McuFusion.UI.Controls
{
    public class MemoryRibbonOrbMenuItem : RibbonOrbMenuItem
    {
        public MemoryRibbonOrbMenuItem(MemoryClassInfo memory)
        {
            this.memory = memory;
            
            this.Style = RibbonButtonStyle.DropDown;
            this.Text = memory.Name;
            this.Image = Resources.OrbImage;

            openItem = new RibbonOrbMenuItem("Open...");
            openItem.Image = Resources.OpenLarge;
            openItem.Click += openItem_Click;

            saveItem = new RibbonOrbMenuItem("Save As...");
            saveItem.Image = Resources.SaveAsLarge;
            saveItem.Click += saveItem_Click;

            this.DropDownItems.Add(new RibbonSeparator(memory.Name));
            this.DropDownItems.Add(openItem);
            this.DropDownItems.Add(saveItem);
        }

        public event MemoryOperationEventHandler OpenFileRequested;

        public event MemoryOperationEventHandler SaveFileRequested;

        private void openItem_Click(object sender, EventArgs e)
        {
            var handler = OpenFileRequested;
            if (handler != null)
            {
                handler(this, new MemoryOperationEventArgs(memory));
            }
        }

        private void saveItem_Click(object sender, EventArgs e)
        {
            var handler = SaveFileRequested;
            if (handler != null)
            {
                handler(this, new MemoryOperationEventArgs(memory));
            }
        }

        private RibbonOrbMenuItem openItem;

        private RibbonOrbMenuItem saveItem;

        private MemoryClassInfo memory;
    }
}
